import configparser
import os

import yaml


def get_project_path():
    cf = os.path.realpath(__file__)
    df = os.path.dirname(cf)
    df = os.path.dirname(df)
    return df + "\\"


def read_ini(path, key):
    path = get_project_path() + path
    config = configparser.ConfigParser()
    config.read(path)
    return config.get("env", key)

def read_yaml(path):
    #读取yaml文件
    #param path文件的相对路径
    path = get_project_path() + path
    #读取文件内容
    with open(path,encoding='utf-8',mode='r') as f:
        content = f.read()
        #将文件转成yaml
        c = yaml.load(content,yaml.FullLoader)
    return c


if __name__ == '__main__':
    print(read_ini(r"env\env.ini", "base_url"))
    db = read_ini(r"env\env.ini", "db")
    print(db)
    print(type(db))
    db2 = eval(db)
    print(db2)
    print(type(db2))

    a = "123"
    b = eval(a)
    print(type(b))
    print(read_yaml(r'data\register_fail.yaml'))